<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
defined('BY_JYA') or exit('error');
cfc('core')->checklogin('jy_jdpm/member.index/');
addmember();
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return=array();
$nickname=pdo_getcolumn('core_members',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_SESSION['uid']),'nickname');
$return['nickname']=$nickname;
$membersinfo=pdo_get('jy_jdpm_member',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']));
set_html('title','安全-'.$this->plugin_setting('basic')['title']);
$message=$this->plugin_setting('message');
$return['info']=$membersinfo;
        // 账户安全等级
        $score = 0;
        if ($membersinfo['verify_mobile'] == 1) {
            $score += 20;
        }
        if ($membersinfo['verify_email'] == 1) {
            $score += 20;
        }
        if (!empty($membersinfo['paypwd'])) {
            $score += 20;
        }
        if ($membersinfo['idcard_check'] == 2) {
            $score += 20;
        }
        if (!empty($membersinfo['question'])) {
            $score += 20;
        }

$return['score']=$score;
if($_RQ['op']=='main'){

	exi($return);
}
if($_RQ['op']=='setpay'){
	$return['info']['paypwd']='';
	$return['is_smscode']=$message['is_smscode'];
	exi($return);
}
if($_RQ['op']=='post1'){
	$postdata=get_postdata();
	if(!$postdata['paypwd'] || strlen($postdata['paypwd'])!=6){
		exi('请输入六位密码','error');
	}
	if($postdata['paypwded']!=$postdata['paypwd']){
		exi('输入密码不一致','error');
	}
	if(!$postdata['verify'] && $message['is_smscode']){
		exi('请输入验证码','error');
	}
	if($postdata['verify']!=$_SESSION['verifycode'] && $message['is_smscode']){
		exi('验证码错误','error');
	}
	unset($_SESSION['verifycode']);
	pdo_update('jy_jdpm_member',array('paypwd'=>encryptPwd(trim($postdata['paypwd']))),array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']));
	if($_SESSION['os']=='windows'){
		exi('修改成功','','main');
	}else{
		exi('修改成功','','goback');
	}
	
}
if($_RQ['op']=='post2'){
	$postdata=get_postdata();
	if(!$postdata['mobile2']&& strlen($postdata['mobile2'])!=11){
		exi('请输入11位手机号','error');
	}
	$verify=verifyME('mobile','verify',$postdata['mobile2'],$_SESSION['uid']);
	if($verify==0){
			exi('手机号已被占用请更换！','error');
	}
	if(!$postdata['code']){
		exi('请输入验证码','error');
	}
	if($postdata['code']!=$_SESSION['verifycode']){
		exi('验证码错误','error');
	}

	$where  = array('mid' => $_SESSION['uid']);
	$mobile = pdo_getcolumn('jy_jdpm_member', $where, 'mobile');
    // 如果原手机号存在为更换手机号【
    if ($mobile) {
          if (!$_SESSION['verifycode'] || $_SESSION['verifycode'] != trim($postdata['code'])) {
                 exi('原绑定手机号的验证码错误，请检查','error');
           }
     }
    // 如果原手机号存在为更换手机号】
	if (!$_SESSION['verifycode2'] || $_SESSION['verifycode2'] != trim($postdata['code2'])) {
                 exi('新绑定手机号的验证码错误，请检查','error');
     }
     if ($postdata['mobile']) {
			$suc = pdo_update('jy_jdpm_member',array('verify_mobile'=>1,'mobile'=>trim($postdata['mobile2'])),array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']));
	 }else{
			$suc = pdo_update('jy_jdpm_member',array('verify_mobile'=>1,'mobile'=>trim($postdata['mobile'])),array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']));
	}
	unset($_SESSION['verifycode']);
	unset($_SESSION['verifycode2']);
	if ($suc) {
					// 更新提醒字段
					exi('认证成功！');
	 } else {
					exi('验证保存失败，请与管理员联系','error');
	 }
	
	exi('修改成功','','main');
}
if($_RQ['op']=='password'){

exi($return);
}
if($_RQ['op']=='send'){
	$postdata=get_postdata();
	$code=rand(100000,999999);
	$msg=array('code'=>$code);
	if($postdata['mobile']){
		$result = $this->model('notice')->set_sms($postdata['mobile'],$msg,0);
		$_SESSION['verifycode']=$code;
	}
	if($postdata['mobile2']){
		$result = $this->model('notice')->set_sms($postdata['mobile2'],$msg,0);
		$_SESSION['verifycode2']=$code;
	}
	if($result){
		exi('success');
	}else{
		exi('error');
	}
	
}
if($_RQ['op']=='send2'){
	$postdata=get_postdata();
	$code=rand(100000,999999);
	$msg=array('code'=>$code);
	if($postdata['mobile']){
		$result = $this->model('notice')->set_sms($postdata['mobile'],$msg,0);
		$_SESSION['verifycode']=$code;
	}
	if($result){
		exi('已成功发送验证码到'.$postdata['mobile'].'请注意查收！','error');
	}else{
		exi('验证码发送失败！','error');
	}
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	$members=pdo_get('core_members',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_SESSION['uid']));
	if(!$postdata['password']){
		exi('请输入原密码','error');
	}
	if(encryptPwd(trim($postdata['password'])) != $members['password']){
		
		exi('原密码错误','error');
	}
	if(!$postdata['password1']){
		exi('请输入新密码','error');
	}
	if($postdata['password1']!=$postdata['password2']){
		exi('2次输入密码不一致','error');
	}	
	pdo_update('core_members',array('password'=>encryptPwd(trim($postdata['password1']))),array('id'=>$_SESSION['uid']));
	if($_SESSION['os']=='windows'){
		exi('修改成功','','main');
	}else{
		exi('修改成功','','member.index/');
	}
}
if($_RQ['op']=='bindphone'){

	exi($return);
}
if($_RQ['op']=='idcard'){
	$return['info']=pdo_get('jy_jdpm_member',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']));
	$return['info']['idcard_front']='';
	$return['info']['idcard_behind']='';
	if($return['info']['idcard_check']==1){
		exi('实名审核中！','error','member.index/');
	}
	if($return['info']['idcard_check']==2){
		exi('实名已认证！','error','member.index/');
	}
	exi($return);
}
if($_RQ['op']=='post3'){
	$postdata=get_postdata();
	if(!$postdata['truename']){
		exi('请输入真实姓名','error');
	}
	if(!$postdata['idcard'] ||  strlen($postdata['idcard'])!=18){
		exi('请输入正确的身份证号','error');
	}
	if(!$postdata['idcard_front'] || !$postdata['idcard_behind']){
		exi('请上传身份证照片','error');
	}
	$postdata['idcard_check']=1;
	pdo_update('jy_jdpm_member',$postdata,array('mid'=>$_SESSION['uid']));
	cfc('message')->setnoticelog('用户“'.$nickname.'”已申请实名认证！请及时处理！',3,manage_url('jy_jdpm/member/realname/idcard_check=1'),$_SESSION['uid']);
	if($_SESSION['os']=='windows'){
		exi('修改成功','','main');
	}else{
		exi('修改成功','','member.index/');
	}
}
